package hu;


import java.util.*;

public class hu88 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] cards = sc.nextLine().split("-");
        String[] card1 = cards[0].split(" ");
        String[] card2 = cards[1].split(" ");
        int[] a = new int[card1.length];
        int[] b = new int[card2.length];
        for (int i = 0; i < card1.length; i++) {
            if(card1[i].equals("J"))
                card1[i] = "11";
            if(card1[i].equals("Q"))
                card1[i] = "12";
            if(card1[i].equals("K"))
                card1[i] = "13";
            if(card1[i].equals("A"))
                card1[i] = "14";
            if(card1[i].equals("2"))
                card1[i] = "15";
            if(card1[i].equals("joker"))
                card1[i] = "16";
            if(card1[i].equals("JOKER"))
                card1[i] = "17";
            a[i] = Integer.parseInt(card1[i]);
        }

        for (int i = 0; i < card2.length; i++) {
            if(card2[i].equals("J"))
                card2[i] = "11";
            if(card2[i].equals("Q"))
                card2[i] = "12";
            if(card2[i].equals("K"))
                card2[i] = "13";
            if(card2[i].equals("A"))
                card2[i] = "14";
            if(card2[i].equals("2"))
                card2[i] = "15";
            if(card2[i].equals("joker"))
                card2[i] = "16";
            if(card2[i].equals("JOKER"))
                card2[i] = "17";
            b[i] = Integer.parseInt(card2[i]);
        }
        if(a.length != b.length){
            if(a.length == 2 && a[0] == 16 && a[1] == 17){
                System.out.println(cards[0]);
                return;
            }
            else if(b.length == 2 && b[0] == 16 && b[1] == 17){
                System.out.println(cards[1]);
                return;
            }
            else if(a.length == 4 && a[0] == a[1] && a[1] == a[2] && a[2] == a[3])
            {
                System.out.println(cards[0]);
                return;

            }
            else if(b.length == 4 && b[0] == b[1] && b[1] == b[2] && b[2] == b[3]){
                System.out.println(cards[1]);
                return;
            }
            else{
                System.out.println("ERROR");
                return;
            }
        }
        else{
            if(a[0] > b[0]){
                System.out.println(cards[0]);
            }
            else{
                System.out.println(cards[1]);
            }
            return;
        }
    }
}
